package com.whfc.ms.api.fuum.service.impl;

import com.whfc.common.exception.BizException;
import com.whfc.common.result.ResultEnum;
import com.whfc.fuum.entity.AppProjectPlan;
import com.whfc.fuum.service.AppProjectPlanService;
import com.whfc.ms.api.fuum.service.MsProjectService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 项目管理控服务
 *
 * @author dzg
 * @since 2025-09-23
 */
@Slf4j
@Service
public class MsProjectServiceImpl implements MsProjectService {

    @DubboReference(interfaceClass = AppProjectPlanService.class, version = "1.0.0")
    private AppProjectPlanService appProjectPlanService;

    @Override
    public AppProjectPlan getById(Integer id) {
        AppProjectPlan appProjectPlan = appProjectPlanService.getById(id);
        if (appProjectPlan == null) {
            throw new BizException(ResultEnum.FAILURE.getCode(), "方案不存在");
        }
        return appProjectPlan;
    }

    @Override
    public List<AppProjectPlan> list(Integer deptId, String planName) {
        return appProjectPlanService.list(deptId, planName);
    }

    @Override
    public boolean save(AppProjectPlan projectPlan) {
        boolean result = appProjectPlanService.save(projectPlan);
        if (!result) throw new BizException(ResultEnum.FAILURE.getCode(), "新增失败");
        return result;
    }

    @Override
    public boolean update(AppProjectPlan projectPlan) {
        AppProjectPlan existingPlan = appProjectPlanService.getById(projectPlan.getId());
        if (existingPlan == null) {
            throw new BizException(ResultEnum.FAILURE.getCode(), "方案不存在");
        }
        boolean result = appProjectPlanService.update(projectPlan);
        if (!result) throw new BizException(ResultEnum.FAILURE.getCode(), "方案不存在");
        return result;
    }

    @Override
    public boolean delete(Integer id) {
        boolean result = appProjectPlanService.delete(id);
        if (!result) throw new BizException(ResultEnum.FAILURE.getCode(), "删除失败");
        return result;
    }

    @Override
    public boolean deleteBatch(List<Integer> ids) {
        boolean result = appProjectPlanService.deleteBatch(ids);
        if (!result) throw new BizException(ResultEnum.FAILURE.getCode(), "批量删除失败");
        return result;
    }
}
